package editAir.editContent
{
	import _me.Scene_data;
	
	import editAir.buildEdit.BuildEditDisplay3DSprite;
	import editAir.buildEdit.EditManage;
	
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.events.MouseEvent;
	import flash.geom.Vector3D;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	
	public class InputModeSprite extends MovieClip
	{
		private var _inputTxt:TextField;
		private var _sacleTxt:TextField;
		private var _addModeBut:MovieClip;
		private var _changeBut:MovieClip;
		private var _newxTxt:TextField;
		private var _newyTxt:TextField;
		private var _newzTxt:TextField;
		private var _lastCentenPosition:Vector3D;
		public function InputModeSprite()
		{
			addBacks();
		    addTexts();
			addInputText();
			addButs();
			addEvents();
		}
		private function addButs():void
		{
			_addModeBut=ModelUiManege.getClass("pic_image_9");
			_addModeBut.x=230
			_addModeBut.y=3
			addChild(_addModeBut);
			
			_changeBut=ModelUiManege.getClass("pic_image_9");
			_changeBut.x=230
			_changeBut.y=33
			addChild(_changeBut);
			

		}
		
		private function addEvents():void
		{
			// TODO Auto Generated method stub
			_addModeBut.addEventListener(MouseEvent.CLICK,addModeButClik)
			_changeBut.addEventListener(MouseEvent.CLICK,changeButClik)
		}
		
		protected function changeButClik(event:MouseEvent):void
		{
			
			var i:int=0;
			var disp3DSprite:BuildEditDisplay3DSprite;
			var sacleNum:Number=Number(_sacleTxt.text);
			var selectVo:ModelVO=ModelUiManege.fileList.getSelectModelVoID();
			if(selectVo){
				var _E:Vector3D=new Vector3D(Number(_newxTxt.text),Number(_newyTxt.text),Number(_newzTxt.text));
	
				if(selectVo.filetype==1){
					if(sacleNum!=selectVo.scale)  //改变大小时不变位置
					{
						for ( i=0; i < EditManage.buildView.selectItem.length; i++)
						{
							disp3DSprite=EditManage.buildView.getBuildSpriteById(EditManage.buildView.selectItem[i]);
							if (disp3DSprite)
							{
								disp3DSprite.scale=sacleNum*disp3DSprite.scale
								ModelUiManege.fileList.changeModelvoPosintAndScale(disp3DSprite);
							}
						}
					}else{
						for ( i=0; i < EditManage.buildView.selectItem.length; i++)
						{
							disp3DSprite=EditManage.buildView.getBuildSpriteById(EditManage.buildView.selectItem[i]);
							if (disp3DSprite)
							{
								disp3DSprite.x=int(disp3DSprite.lastx + (_E.x - _lastCentenPosition.x));
								disp3DSprite.z=int(disp3DSprite.lastz + (_E.z - _lastCentenPosition.z));
								ModelUiManege.fileList.changeModelvoPosintAndScale(disp3DSprite);
							}
						}
					}
					
				}else{
				
					disp3DSprite=EditManage.buildView.getBuildSpriteById(selectVo.id);
					if (disp3DSprite)
					{
						disp3DSprite.x=int(disp3DSprite.lastx + (_E.x - _lastCentenPosition.x));
						disp3DSprite.z=int(disp3DSprite.lastz + (_E.z - _lastCentenPosition.z));
						if(sacleNum>0){
							disp3DSprite.scale=sacleNum;
						}
						ModelUiManege.fileList.changeModelvoPosintAndScale(disp3DSprite);
					}
				}
				
			}
			

		}

		protected function addModeButClik(event:MouseEvent):void
		{
			var tempModelVo:ModelVO=new ModelVO;
			tempModelVo.name=_inputTxt.text
			tempModelVo.et=_inputTxt.text
			tempModelVo.id= ModelUiManege.fileList.getRandomNewId()
			tempModelVo.open=false;
			tempModelVo.filetype=0;
			var selectVo:ModelVO=ModelUiManege.fileList.getSelectModelVoID();
			if(selectVo){
				if(selectVo.filetype==1){
					tempModelVo.father=selectVo.id;
				}else{
					tempModelVo.father=selectVo.father;
				}
			}else{
				tempModelVo.father=0;
			}
			
			if(Number(_sacleTxt.text)){
				tempModelVo.scale=Number(_sacleTxt.text);
			}else{
				tempModelVo.scale=1;
			}
			tempModelVo.bh=DataType.NUM25
			tempModelVo.x=Scene_data.focus3D.x;
			tempModelVo.y=0;
			tempModelVo.z=Scene_data.focus3D.z;

			ModelUiManege.fileList.pushModelVoToList(tempModelVo);
			ModelUiManege.fileList.modelItem.push(tempModelVo)
			ModelUiManege.fileList.changePasition();
			
		}
		private function addInputText():void
		{
			// TODO Auto Generated method stub
			var thistextformat:TextFormat=new TextFormat;
			_inputTxt= new TextField()
			_inputTxt.defaultTextFormat = thistextformat;
			_inputTxt.htmlText="box512";
			_inputTxt.width=100;
			_inputTxt.height=20;
			_inputTxt.type = TextFieldType.INPUT;
			_inputTxt.x=100;
			_inputTxt.y=3;
			addChild(_inputTxt);
			
			
			
			
			_sacleTxt= new TextField()
			_sacleTxt.defaultTextFormat = thistextformat;
			_sacleTxt.htmlText="1";
			_sacleTxt.width=30;
			_sacleTxt.height=20
			_sacleTxt.type = TextFieldType.INPUT;
			_sacleTxt.x=200;
			_sacleTxt.y=3;
			addChild(_sacleTxt);
			
			
			
			_newxTxt= new TextField()
			_newxTxt.defaultTextFormat = thistextformat;
			_newxTxt.htmlText="500";
			_newxTxt.width=50;
			_newxTxt.height=20
			_newxTxt.type = TextFieldType.INPUT;
			_newxTxt.x=20;
			_newxTxt.y=30;
			addChild(_newxTxt);
			
			_newyTxt= new TextField()
			_newyTxt.defaultTextFormat = thistextformat;
			_newyTxt.htmlText="500";
			_newyTxt.width=50;
			_newyTxt.height=20
			_newyTxt.type = TextFieldType.INPUT;
			_newyTxt.x=90;
			_newyTxt.y=30;
			addChild(_newyTxt);
			
			_newzTxt= new TextField()
			_newzTxt.defaultTextFormat = thistextformat;
			_newzTxt.htmlText="500";
			_newzTxt.width=50;
			_newzTxt.height=20
			_newzTxt.type = TextFieldType.INPUT;
			_newzTxt.x=160;
			_newzTxt.y=30;
			addChild(_newzTxt);
		}
		public function setChooseModelVoid(id:uint):void
		{
			if (EditManage.buildView.selectItem && EditManage.buildView.selectItem.length)
			{
				for (var i:int=0; i < EditManage.buildView.selectItem.length; i++)
				{
					var disp3DSprite:BuildEditDisplay3DSprite=EditManage.buildView.getBuildSpriteById(EditManage.buildView.selectItem[i]);
					if (disp3DSprite)
					{
						disp3DSprite.lastx=disp3DSprite.x;
						disp3DSprite.lasty=disp3DSprite.y;
						disp3DSprite.lastz=disp3DSprite.z;
					}
				}
			}
			 _lastCentenPosition=ModelUiManege.fileList.getSelectItemCenten(EditManage.buildView.selectItem)
			if(_lastCentenPosition)
			{
				_newxTxt.text=String(int(_lastCentenPosition.x));
				_newyTxt.text=String(int(_lastCentenPosition.y));
				_newzTxt.text=String(int(_lastCentenPosition.z));
			}
			
			var selectVo:ModelVO=ModelUiManege.fileList.getSelectModelVoID();
			if(selectVo){
				_sacleTxt.text=String(selectVo.scale);
			}
		
		}

		private function addBacks():void
		{
			var backPic:Shape=new Shape;
			addChild(backPic);
			backPic.graphics.beginFill(0xffffff, 1);
			backPic.graphics.drawRect(90, 0, 100, 25);
	
			backPic.graphics.drawRect(195, 0, 30, 25);
			
			
			backPic.graphics.drawRect(20, 30, 50, 22);
			backPic.graphics.drawRect(90, 30, 50, 22);
			backPic.graphics.drawRect(160, 30, 50, 22);
			
			
			
			backPic.graphics.endFill();
		
		}
		
		private function addTexts():void
		{
			var titleTxt:TextField=FileTextUtil.getTextField();
			titleTxt.htmlText="输入模型名字";
			addChild(titleTxt);
			titleTxt.x=0;
			titleTxt.y=3;
			
			
			var xtext:TextField=FileTextUtil.getTextField();
			xtext.htmlText="x:";
			addChild(xtext);
			xtext.x=5;
			xtext.y=30;
			
			var ytext:TextField=FileTextUtil.getTextField();
			ytext.htmlText="y:";
			addChild(ytext);
			ytext.x=75;
			ytext.y=30;
			
			var ztext:TextField=FileTextUtil.getTextField();
			ztext.htmlText="z:";
			addChild(ztext);
			ztext.x=145;
			ztext.y=30;
			
			
		}
	}
}